//
//  YGConsultListTableViewCell.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/8.
//

#import "YGConsultListTableViewCell.h"
#import "YGExpertsListTableViewCell.h"

@interface YGConsultListTableViewCell ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *expertsArry;




@end

@implementation YGConsultListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initconstraints];
    }
    return self;
}

-(void)initView{
    [self.contentView addSubview:self.tableView];
    [self.contentView addSubview:self.titleLabel];
    _expertsArry = [NSMutableArray array];
}

-(void)initconstraints{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView.mas_top).offset(20);
            make.left.mas_equalTo(self.contentView.mas_left).offset(10);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(15);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(20);
            make.left.mas_equalTo(self.titleLabel.mas_left);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
            make.height.mas_equalTo(self.contentView.mas_height);
    }];
}

-(void)configureDataWith:(NSArray *)model{
    if (model) {
        [_expertsArry addObjectsFromArray:model];
        [self.tableView reloadData];
    }
}

#pragma delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _expertsArry.count;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.00001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 140;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.000001;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YGExpertsListTableViewCell *cell = [[YGExpertsListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YGExpertsListTableViewCell"];
    YGExpertMsgModel *model = [self.expertsArry objectAtIndex:indexPath.row];
    [cell configuraDataWith:model];
    return cell;
}

#pragma setter
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        [_tableView registerClass:YGExpertsListTableViewCell.class forCellReuseIdentifier:@"YGExpertsListTableViewCell"];
        [_tableView registerClass:YGExpertsListTableViewCell.class forCellReuseIdentifier:@"YGExpertsListTableViewCell"];
    }
    return _tableView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"咨询列表";
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = UIColorFromRGB(0x333333);
    }
    return _titleLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
